package com.xy.biz.fd.domain.converter;

import java.util.Collection;
import java.util.List;

import com.xy.biz.fd.domain.bo.FolderBO;
import com.xy.biz.fd.domain.po.FolderPO;
import com.xy.biz.fd.domain.query.FolderQuery;
import com.xy.biz.fd.domain.req.folder.ListFolderRequest;
import com.xy.biz.fd.domain.req.folder.SaveFolderRequest;
import com.xy.biz.fd.domain.resp.GetFolderResponse;
import com.xy.tool.util.BeanUtilsEx;

/**
 * 
 * 
 * @author ssl
 * @date 2021-1-23
 */
public class FolderConverter {
	
	public static FolderPO toPO(FolderBO source) {
		return BeanUtilsEx.copyProperties(source, () -> new FolderPO(), true);
	}
	
	public static List<FolderPO> toPO(Collection<FolderBO> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new FolderPO(), true);
	}
	
	public static FolderBO fromPO(FolderPO source) {
		return BeanUtilsEx.copyProperties(source, () -> new FolderBO());
	}
	
	public static List<FolderBO> fromPO(Collection<FolderPO> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new FolderBO());
	}
	
	public static FolderBO toBO(SaveFolderRequest source) {
		return BeanUtilsEx.copyProperties(source, () -> new FolderBO(), true);
	}

	public static List<FolderBO> toBO(Collection<SaveFolderRequest> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new FolderBO(), true);
	}
	
	public static GetFolderResponse toResponse(FolderBO source) {
		return BeanUtilsEx.copyProperties(source, () -> new GetFolderResponse());
	}
	
	public static List<GetFolderResponse> toResponse(Collection<FolderBO> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new GetFolderResponse());
	}
	
	public static FolderQuery toQuery(ListFolderRequest source) {
		if(null == source) {
			return null;
		}
		FolderQuery target = new FolderQuery(source.getPageIndex(), source.getPageSize());
		BeanUtilsEx.copyProperties(source, target);
		return target;
	}

	public static FolderQuery toQuery(FolderBO source) {
		if(null == source) {
			return null;
		}
		FolderQuery target = FolderQuery.one().build();
		BeanUtilsEx.copyProperties(source, target);
		return target;
	}

}
